/*
 * LastPlaylistView.java
 */
package lastplaylist;

import com.dt.iTunesController.ITArtworkCollection;
import com.dt.iTunesController.ITArtworkFormat;
import com.dt.iTunesController.ITLibraryPlaylist;
import com.dt.iTunesController.ITPlayerState;
import com.dt.iTunesController.ITPlaylist;
import com.dt.iTunesController.ITPlaylistSearchField;
import com.dt.iTunesController.ITTrack;
import com.dt.iTunesController.ITTrackCollection;
import com.dt.iTunesController.ITUserPlaylist;
import com.dt.iTunesController.iTunes;
//import com.jacob.com.DispatchEvents;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import java.awt.Component;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ListModel;
import net.roarsoftware.lastfm.Chart;
import net.roarsoftware.lastfm.PaginatedResult;
import org.jdesktop.application.Action;
import org.jdesktop.application.ResourceMap;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.FrameView;
import org.jdesktop.application.Task;
import org.jdesktop.application.TaskMonitor;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.net.URL;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import javax.imageio.ImageIO;
import javax.swing.DefaultCellEditor;
import javax.swing.DefaultListModel;
import javax.swing.Timer;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
import net.homeip.fosa.letrasapi.Pagina;
import net.homeip.fosa.letrasapi.Search;
import net.roarsoftware.lastfm.Artist;
import net.roarsoftware.lastfm.Authenticator;
import net.roarsoftware.lastfm.ImageSize;
import net.roarsoftware.lastfm.Period;
import net.roarsoftware.lastfm.Session;
import net.roarsoftware.lastfm.Tag;
import net.roarsoftware.lastfm.Track;
import net.roarsoftware.lastfm.User;
import system.Options;

/**
 * The application's main frame.
 */
public class LastPlaylistView extends FrameView {

    public LastPlaylistView(SingleFrameApplication app) {
        super(app);

        initComponents();

        // status bar initialization - message timeout, idle icon and busy animation, etc
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++) {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener() {

            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName)) {
                    if (!busyIconTimer.isRunning()) {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                } else if ("done".equals(propertyName)) {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                } else if ("message".equals(propertyName)) {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                } else if ("progress".equals(propertyName)) {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }

    @Action
    public void showAboutBox() {
        if (aboutBox == null) {
            JFrame mainFrame = LastPlaylistApp.getApplication().getMainFrame();
            aboutBox = new LastPlaylistAboutBox(mainFrame);
            aboutBox.setLocationRelativeTo(mainFrame);
        }
        LastPlaylistApp.getApplication().show(aboutBox);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        mainPanel = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        PrevButton = new javax.swing.JButton();
        NextButton = new javax.swing.JButton();
        PlayPauseButton = new javax.swing.JButton();
        jSplitPane1 = new javax.swing.JSplitPane();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        UserPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel2 = new javax.swing.JPanel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jComboBox1 = new javax.swing.JComboBox();
        jButton2 = new javax.swing.JButton();
        UserPeriodComboBox = new javax.swing.JComboBox();
        ArtistPanel = new javax.swing.JPanel();
        jPanel5 = new javax.swing.JPanel();
        jTextField3 = new javax.swing.JTextField();
        jButton8 = new javax.swing.JButton();
        jComboBox3 = new javax.swing.JComboBox();
        jButton9 = new javax.swing.JButton();
        jComboBox5 = new javax.swing.JComboBox();
        jScrollPane4 = new javax.swing.JScrollPane();
        jTable3 = new javax.swing.JTable();
        TagPanel = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jTextField2 = new javax.swing.JTextField();
        jButton3 = new javax.swing.JButton();
        jComboBox2 = new javax.swing.JComboBox();
        jButton4 = new javax.swing.JButton();
        jComboBox6 = new javax.swing.JComboBox();
        jScrollPane3 = new javax.swing.JScrollPane();
        jTable2 = new javax.swing.JTable();
        ToolsPanel = new javax.swing.JPanel();
        jPanel9 = new javax.swing.JPanel();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jPanel10 = new javax.swing.JPanel();
        jRadioButton5 = new javax.swing.JRadioButton();
        jRadioButton6 = new javax.swing.JRadioButton();
        jRadioButton7 = new javax.swing.JRadioButton();
        jRadioButton16 = new javax.swing.JRadioButton();
        LyricsPanel = new javax.swing.JPanel();
        jSplitPane2 = new javax.swing.JSplitPane();
        jScrollPane5 = new javax.swing.JScrollPane();
        TrackList = new javax.swing.JList();
        jPanel6 = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        TrackLyric = new javax.swing.JTextArea();
        jButton10 = new javax.swing.JButton();
        jToggleButton1 = new javax.swing.JToggleButton();
        GoLyrics = new javax.swing.JButton();
        jComboBox4 = new javax.swing.JComboBox();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        menuBar = new javax.swing.JMenuBar();
        javax.swing.JMenu fileMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem exitMenuItem = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        javax.swing.JMenu helpMenu = new javax.swing.JMenu();
        javax.swing.JMenuItem aboutMenuItem = new javax.swing.JMenuItem();
        statusPanel = new javax.swing.JPanel();
        javax.swing.JSeparator statusPanelSeparator = new javax.swing.JSeparator();
        statusMessageLabel = new javax.swing.JLabel();
        statusAnimationLabel = new javax.swing.JLabel();
        progressBar = new javax.swing.JProgressBar();
        UserPeriod = new javax.swing.ButtonGroup();
        ImportMode = new javax.swing.ButtonGroup();
        LyricsModeButtonGroup = new javax.swing.ButtonGroup();
        buttonGroup1 = new javax.swing.ButtonGroup();

        mainPanel.setName("mainPanel"); // NOI18N

        jPanel3.setName("jPanel3"); // NOI18N

        javax.swing.ActionMap actionMap = org.jdesktop.application.Application.getInstance(lastplaylist.LastPlaylistApp.class).getContext().getActionMap(LastPlaylistView.class, this);
        PrevButton.setAction(actionMap.get("prev")); // NOI18N
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(lastplaylist.LastPlaylistApp.class).getContext().getResourceMap(LastPlaylistView.class);
        PrevButton.setText(resourceMap.getString("PrevButton.text")); // NOI18N
        PrevButton.setName("PrevButton"); // NOI18N
        PrevButton.setPressedIcon(resourceMap.getIcon("PrevButton.pressedIcon")); // NOI18N

        NextButton.setAction(actionMap.get("next")); // NOI18N
        NextButton.setText(resourceMap.getString("NextButton.text")); // NOI18N
        NextButton.setName("NextButton"); // NOI18N
        NextButton.setPressedIcon(resourceMap.getIcon("NextButton.pressedIcon")); // NOI18N

        PlayPauseButton.setAction(actionMap.get("PlayPause")); // NOI18N
        PlayPauseButton.setText(resourceMap.getString("PlayPauseButton.text")); // NOI18N
        PlayPauseButton.setName("PlayPauseButton"); // NOI18N

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(PrevButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PlayPauseButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(NextButton)
                .addContainerGap(452, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(PlayPauseButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(PrevButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(NextButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        jSplitPane1.setDividerLocation(300);
        jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
        jSplitPane1.setResizeWeight(0.9);
        jSplitPane1.setName("jSplitPane1"); // NOI18N

        jTabbedPane1.setName("jTabbedPane1"); // NOI18N

        UserPanel.setName("UserPanel"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTable1.setAutoCreateRowSorter(true);
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "✓", "Nome", "Artista", "Album", "More", "Tag"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                true, false, false, false, false, true
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable1.setName("jTable1"); // NOI18N
        jTable1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable1MouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumn(jTable1.getColumnName(0)).setCellEditor(new DefaultCellEditor(new JCheckBox()));

        jTable1.getColumn(jTable1.getColumnName(0)).setCellRenderer(new TableCellRenderer() {

            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                JCheckBox checkbox = new JCheckBox();
                checkbox.setSelected(Boolean.parseBoolean(value.toString()));
                return checkbox;
            }
        });

        jPanel2.setName("jPanel2"); // NOI18N

        jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
        jTextField1.setAction(actionMap.get("getXML")); // NOI18N
        jTextField1.setName("jTextField1"); // NOI18N

        jButton1.setAction(actionMap.get("getLastfmData")); // NOI18N
        jButton1.setText(resourceMap.getString("jButton1.text")); // NOI18N
        jButton1.setName("jButton1"); // NOI18N

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Limit:", "25", "50", "100", "200" }));
        jComboBox1.setName("jComboBox1"); // NOI18N

        jButton2.setAction(actionMap.get("gerarLista")); // NOI18N
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N

        UserPeriodComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Period:", "Last week chart", "Last 3 months", "Last 7 days", "Love Tracks" }));
        UserPeriodComboBox.setName("UserPeriodComboBox"); // NOI18N

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 309, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(UserPeriodComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2)
                    .addComponent(jButton1)
                    .addComponent(UserPeriodComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout UserPanelLayout = new javax.swing.GroupLayout(UserPanel);
        UserPanel.setLayout(UserPanelLayout);
        UserPanelLayout.setHorizontalGroup(
            UserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 614, Short.MAX_VALUE)
        );
        UserPanelLayout.setVerticalGroup(
            UserPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(UserPanelLayout.createSequentialGroup()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("UserPanel.TabConstraints.tabTitle"), UserPanel); // NOI18N

        ArtistPanel.setName("ArtistPanel"); // NOI18N

        jPanel5.setName("jPanel5"); // NOI18N

        jTextField3.setText(resourceMap.getString("jTextField3.text")); // NOI18N
        jTextField3.setAction(actionMap.get("getXML")); // NOI18N
        jTextField3.setName("jTextField3"); // NOI18N
        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });

        jButton8.setAction(actionMap.get("getArtist")); // NOI18N
        jButton8.setText(resourceMap.getString("jButton8.text")); // NOI18N
        jButton8.setName("jButton8"); // NOI18N

        jComboBox3.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "25", "50", "100", "200" }));
        jComboBox3.setSelectedIndex(2);
        jComboBox3.setEnabled(false);
        jComboBox3.setName("jComboBox3"); // NOI18N

        jButton9.setAction(actionMap.get("gerarLista")); // NOI18N
        jButton9.setText(resourceMap.getString("jButton9.text")); // NOI18N
        jButton9.setEnabled(false);
        jButton9.setName("jButton9"); // NOI18N

        jComboBox5.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tracks of:", "Playing Track", "Selected Tracks", "Playing Playlist", "Whole Library" }));
        jComboBox5.setEnabled(false);
        jComboBox5.setName("jComboBox5"); // NOI18N

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField3, javax.swing.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton9)
                    .addComponent(jComboBox5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton8))
                .addContainerGap())
        );

        jScrollPane4.setName("jScrollPane4"); // NOI18N

        jTable3.setAutoCreateRowSorter(true);
        jTable3.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "Sumário"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable3.setName("jTable3"); // NOI18N
        jTable3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTable3MouseClicked(evt);
            }
        });
        jScrollPane4.setViewportView(jTable3);
        jTable1.getColumn(jTable1.getColumnName(0)).setCellEditor(new DefaultCellEditor(new JCheckBox()));

        jTable1.getColumn(jTable1.getColumnName(0)).setCellRenderer(new TableCellRenderer() {

            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                JCheckBox checkbox = new JCheckBox();
                checkbox.setSelected(Boolean.parseBoolean(value.toString()));
                return checkbox;
            }
        });

        javax.swing.GroupLayout ArtistPanelLayout = new javax.swing.GroupLayout(ArtistPanel);
        ArtistPanel.setLayout(ArtistPanelLayout);
        ArtistPanelLayout.setHorizontalGroup(
            ArtistPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 614, Short.MAX_VALUE)
        );
        ArtistPanelLayout.setVerticalGroup(
            ArtistPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ArtistPanelLayout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("ArtistPanel.TabConstraints.tabTitle"), ArtistPanel); // NOI18N

        TagPanel.setName("TagPanel"); // NOI18N

        jPanel4.setName("jPanel4"); // NOI18N

        jTextField2.setText(resourceMap.getString("jTextField2.text")); // NOI18N
        jTextField2.setAction(actionMap.get("getXML")); // NOI18N
        jTextField2.setName("jTextField2"); // NOI18N
        jTextField2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField2ActionPerformed(evt);
            }
        });

        jButton3.setAction(actionMap.get("getTags")); // NOI18N
        jButton3.setText(resourceMap.getString("jButton3.text")); // NOI18N
        jButton3.setName("jButton3"); // NOI18N

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "25", "50", "100", "200" }));
        jComboBox2.setSelectedIndex(2);
        jComboBox2.setEnabled(false);
        jComboBox2.setName("jComboBox2"); // NOI18N

        jButton4.setAction(actionMap.get("gerarLista")); // NOI18N
        jButton4.setText(resourceMap.getString("jButton4.text")); // NOI18N
        jButton4.setEnabled(false);
        jButton4.setName("jButton4"); // NOI18N

        jComboBox6.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tracks of:", "Playing Track", "Selected Tracks", "Playing Playlist", "Whole Library" }));
        jComboBox6.setEnabled(false);
        jComboBox6.setName("jComboBox6"); // NOI18N

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 301, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jComboBox2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton4)
                    .addComponent(jComboBox6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton3))
                .addContainerGap())
        );

        jScrollPane3.setName("jScrollPane3"); // NOI18N

        jTable2.setAutoCreateRowSorter(true);
        jTable2.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nome", "Quantidade"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable2.setName("jTable2"); // NOI18N
        jScrollPane3.setViewportView(jTable2);
        jTable1.getColumn(jTable1.getColumnName(0)).setCellEditor(new DefaultCellEditor(new JCheckBox()));

        jTable1.getColumn(jTable1.getColumnName(0)).setCellRenderer(new TableCellRenderer() {

            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                JCheckBox checkbox = new JCheckBox();
                checkbox.setSelected(Boolean.parseBoolean(value.toString()));
                return checkbox;
            }
        });

        javax.swing.GroupLayout TagPanelLayout = new javax.swing.GroupLayout(TagPanel);
        TagPanel.setLayout(TagPanelLayout);
        TagPanelLayout.setHorizontalGroup(
            TagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 614, Short.MAX_VALUE)
        );
        TagPanelLayout.setVerticalGroup(
            TagPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(TagPanelLayout.createSequentialGroup()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 236, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab(resourceMap.getString("TagPanel.TabConstraints.tabTitle"), TagPanel); // NOI18N

        ToolsPanel.setName("ToolsPanel"); // NOI18N

        jPanel9.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel9.border.title"))); // NOI18N
        jPanel9.setName("jPanel9"); // NOI18N

        jButton5.setAction(actionMap.get("getDataFromLastFmToItunes")); // NOI18N
        jButton5.setText(resourceMap.getString("jButton5.text")); // NOI18N
        jButton5.setName("jButton5"); // NOI18N

        jButton6.setAction(actionMap.get("getArtOfTrackFromLastFm")); // NOI18N
        jButton6.setText(resourceMap.getString("jButton6.text")); // NOI18N
        jButton6.setName("jButton6"); // NOI18N

        jButton7.setAction(actionMap.get("getTagsFromLastfmToItunes")); // NOI18N
        jButton7.setText(resourceMap.getString("jButton7.text")); // NOI18N
        jButton7.setName("jButton7"); // NOI18N

        javax.swing.GroupLayout jPanel9Layout = new javax.swing.GroupLayout(jPanel9);
        jPanel9.setLayout(jPanel9Layout);
        jPanel9Layout.setHorizontalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(jButton7, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton6, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel9Layout.setVerticalGroup(
            jPanel9Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel9Layout.createSequentialGroup()
                .addComponent(jButton5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton7)
                .addContainerGap(168, Short.MAX_VALUE))
        );

        jPanel10.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel10.border.title"))); // NOI18N
        jPanel10.setName("jPanel10"); // NOI18N

        ImportMode.add(jRadioButton5);
        jRadioButton5.setText(resourceMap.getString("jRadioButton5.text")); // NOI18N
        jRadioButton5.setName("jRadioButton5"); // NOI18N

        ImportMode.add(jRadioButton6);
        jRadioButton6.setText(resourceMap.getString("jRadioButton6.text")); // NOI18N
        jRadioButton6.setName("jRadioButton6"); // NOI18N

        ImportMode.add(jRadioButton7);
        jRadioButton7.setText(resourceMap.getString("jRadioButton7.text")); // NOI18N
        jRadioButton7.setName("jRadioButton7"); // NOI18N

        ImportMode.add(jRadioButton16);
        jRadioButton16.setText(resourceMap.getString("jRadioButton16.text")); // NOI18N
        jRadioButton16.setName("jRadioButton16"); // NOI18N

        javax.swing.GroupLayout jPanel10Layout = new javax.swing.GroupLayout(jPanel10);
        jPanel10.setLayout(jPanel10Layout);
        jPanel10Layout.setHorizontalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jRadioButton16)
                    .addComponent(jRadioButton6)
                    .addComponent(jRadioButton7)
                    .addComponent(jRadioButton5))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel10Layout.setVerticalGroup(
            jPanel10Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel10Layout.createSequentialGroup()
                .addComponent(jRadioButton16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jRadioButton7)
                .addContainerGap(157, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout ToolsPanelLayout = new javax.swing.GroupLayout(ToolsPanel);
        ToolsPanel.setLayout(ToolsPanelLayout);
        ToolsPanelLayout.setHorizontalGroup(
            ToolsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(ToolsPanelLayout.createSequentialGroup()
                .addComponent(jPanel9, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel10, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(354, Short.MAX_VALUE))
        );
        ToolsPanelLayout.setVerticalGroup(
            ToolsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel9, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel10, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        jTabbedPane1.addTab(resourceMap.getString("ToolsPanel.TabConstraints.tabTitle"), ToolsPanel); // NOI18N

        LyricsPanel.setName("LyricsPanel"); // NOI18N

        jSplitPane2.setDividerLocation(200);
        jSplitPane2.setName("jSplitPane2"); // NOI18N

        jScrollPane5.setName("jScrollPane5"); // NOI18N

        TrackList.setName("TrackList"); // NOI18N
        TrackList.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TrackListMouseClicked(evt);
            }
        });
        jScrollPane5.setViewportView(TrackList);

        jSplitPane2.setLeftComponent(jScrollPane5);

        jPanel6.setName("jPanel6"); // NOI18N

        jScrollPane6.setName("jScrollPane6"); // NOI18N

        TrackLyric.setColumns(20);
        TrackLyric.setRows(5);
        TrackLyric.setName("TrackLyric"); // NOI18N
        jScrollPane6.setViewportView(TrackLyric);

        jButton10.setText(resourceMap.getString("jButton10.text")); // NOI18N
        jButton10.setName("jButton10"); // NOI18N

        jToggleButton1.setText(resourceMap.getString("jToggleButton1.text")); // NOI18N
        jToggleButton1.setName("jToggleButton1"); // NOI18N
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jButton10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jToggleButton1)
                .addContainerGap(246, Short.MAX_VALUE))
            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE))
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel6Layout.createSequentialGroup()
                .addContainerGap(209, Short.MAX_VALUE)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton10)
                    .addComponent(jToggleButton1)))
            .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel6Layout.createSequentialGroup()
                    .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 202, Short.MAX_VALUE)
                    .addGap(30, 30, 30)))
        );

        jSplitPane2.setRightComponent(jPanel6);

        GoLyrics.setAction(actionMap.get("getTracksFromItunes")); // NOI18N
        GoLyrics.setText(resourceMap.getString("GoLyrics.text")); // NOI18N
        GoLyrics.setName("GoLyrics"); // NOI18N

        jComboBox4.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Tracks of:", "Playing Track", "Selected Tracks", "Playing Playlist", "Whole Library" }));
        jComboBox4.setName("jComboBox4"); // NOI18N

        javax.swing.GroupLayout LyricsPanelLayout = new javax.swing.GroupLayout(LyricsPanel);
        LyricsPanel.setLayout(LyricsPanelLayout);
        LyricsPanelLayout.setHorizontalGroup(
            LyricsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(LyricsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(GoLyrics)
                .addContainerGap(453, Short.MAX_VALUE))
            .addGroup(LyricsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 614, Short.MAX_VALUE))
        );
        LyricsPanelLayout.setVerticalGroup(
            LyricsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(LyricsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(LyricsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jComboBox4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(GoLyrics))
                .addContainerGap(242, Short.MAX_VALUE))
            .addGroup(LyricsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, LyricsPanelLayout.createSequentialGroup()
                    .addGap(42, 42, 42)
                    .addComponent(jSplitPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 234, Short.MAX_VALUE)))
        );

        jTabbedPane1.addTab(resourceMap.getString("LyricsPanel.TabConstraints.tabTitle"), LyricsPanel); // NOI18N

        jSplitPane1.setTopComponent(jTabbedPane1);

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setName("jTextArea1"); // NOI18N
        jScrollPane2.setViewportView(jTextArea1);

        jSplitPane1.setRightComponent(jScrollPane2);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE)
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 334, Short.MAX_VALUE))
        );

        menuBar.setName("menuBar"); // NOI18N

        fileMenu.setText(resourceMap.getString("fileMenu.text")); // NOI18N
        fileMenu.setName("fileMenu"); // NOI18N

        exitMenuItem.setAction(actionMap.get("quit")); // NOI18N
        exitMenuItem.setName("exitMenuItem"); // NOI18N
        fileMenu.add(exitMenuItem);

        menuBar.add(fileMenu);

        jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
        jMenu1.setName("jMenu1"); // NOI18N

        jMenuItem1.setText(resourceMap.getString("jMenuItem1.text")); // NOI18N
        jMenuItem1.setName("jMenuItem1"); // NOI18N
        jMenu1.add(jMenuItem1);

        menuBar.add(jMenu1);

        helpMenu.setText(resourceMap.getString("helpMenu.text")); // NOI18N
        helpMenu.setName("helpMenu"); // NOI18N

        aboutMenuItem.setAction(actionMap.get("showAboutBox")); // NOI18N
        aboutMenuItem.setName("aboutMenuItem"); // NOI18N
        helpMenu.add(aboutMenuItem);

        menuBar.add(helpMenu);

        statusPanel.setName("statusPanel"); // NOI18N

        statusPanelSeparator.setName("statusPanelSeparator"); // NOI18N

        statusMessageLabel.setName("statusMessageLabel"); // NOI18N
        statusMessageLabel.addPropertyChangeListener(new java.beans.PropertyChangeListener() {
            public void propertyChange(java.beans.PropertyChangeEvent evt) {
                statusMessageLabelPropertyChange(evt);
            }
        });

        statusAnimationLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        statusAnimationLabel.setName("statusAnimationLabel"); // NOI18N

        progressBar.setName("progressBar"); // NOI18N

        javax.swing.GroupLayout statusPanelLayout = new javax.swing.GroupLayout(statusPanel);
        statusPanel.setLayout(statusPanelLayout);
        statusPanelLayout.setHorizontalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(statusPanelSeparator, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(statusMessageLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 451, Short.MAX_VALUE)
                .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(statusAnimationLabel)
                .addContainerGap())
        );
        statusPanelLayout.setVerticalGroup(
            statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(statusPanelLayout.createSequentialGroup()
                .addComponent(statusPanelSeparator, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(statusPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(statusMessageLabel)
                    .addComponent(statusAnimationLabel)
                    .addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(3, 3, 3))
        );

        setComponent(mainPanel);
        setMenuBar(menuBar);
        setStatusBar(statusPanel);
    }// </editor-fold>//GEN-END:initComponents

    private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked
        if (evt.getClickCount() > 1) {
            try {
                iTunes it = new iTunes();
                String nome = (String) jTable1.getValueAt(jTable1.getSelectedRow(), 1);
                String artista = (String) jTable1.getValueAt(jTable1.getSelectedRow(), 2);
                ITTrackCollection tracks = it.getCurrentPlaylist().search(nome + "" + artista, ITPlaylistSearchField.ITPlaylistSearchFieldAll);
                ITTrack track = tracks.ItemByName(nome);
                track.play();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }//GEN-LAST:event_jTable1MouseClicked

    private void statusMessageLabelPropertyChange(java.beans.PropertyChangeEvent evt) {//GEN-FIRST:event_statusMessageLabelPropertyChange
        jTextArea1.setText(jTextArea1.getText() + (statusMessageLabel.getText().equals("") ? "" : "\n" + statusMessageLabel.getText()));
    }//GEN-LAST:event_statusMessageLabelPropertyChange

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField2ActionPerformed
        new GetTagsTask(getApplication()).execute();
    }//GEN-LAST:event_jTextField2ActionPerformed

    private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed
        new GetArtistTask(getApplication()).execute();
    }//GEN-LAST:event_jTextField3ActionPerformed

    private void jTable3MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable3MouseClicked
    }//GEN-LAST:event_jTable3MouseClicked

    private void TrackListMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TrackListMouseClicked
        String faixa = TrackList.getSelectedValue().toString();
        String letra = tracklyricmap.get(faixa);
        TrackLyric.setText(letra);
    }//GEN-LAST:event_TrackListMouseClicked

    private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleButton1ActionPerformed
        jButton10.setEnabled(!jToggleButton1.isSelected());
    }//GEN-LAST:event_jToggleButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel ArtistPanel;
    private javax.swing.JButton GoLyrics;
    private javax.swing.ButtonGroup ImportMode;
    private javax.swing.ButtonGroup LyricsModeButtonGroup;
    private javax.swing.JPanel LyricsPanel;
    private javax.swing.JButton NextButton;
    private javax.swing.JButton PlayPauseButton;
    private javax.swing.JButton PrevButton;
    private javax.swing.JPanel TagPanel;
    private javax.swing.JPanel ToolsPanel;
    private javax.swing.JList TrackList;
    private javax.swing.JTextArea TrackLyric;
    private javax.swing.JPanel UserPanel;
    private javax.swing.ButtonGroup UserPeriod;
    private javax.swing.JComboBox UserPeriodComboBox;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JComboBox jComboBox3;
    private javax.swing.JComboBox jComboBox4;
    private javax.swing.JComboBox jComboBox5;
    private javax.swing.JComboBox jComboBox6;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JPanel jPanel10;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel9;
    private javax.swing.JRadioButton jRadioButton16;
    private javax.swing.JRadioButton jRadioButton5;
    private javax.swing.JRadioButton jRadioButton6;
    private javax.swing.JRadioButton jRadioButton7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JTable jTable1;
    private javax.swing.JTable jTable2;
    private javax.swing.JTable jTable3;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JProgressBar progressBar;
    private javax.swing.JLabel statusAnimationLabel;
    private javax.swing.JLabel statusMessageLabel;
    private javax.swing.JPanel statusPanel;
    // End of variables declaration//GEN-END:variables
    private final Timer messageTimer;
    private final Timer busyIconTimer;
    private final Icon idleIcon;
    private final Icon[] busyIcons = new Icon[15];
    private int busyIconIndex = 0;
    private JDialog aboutBox;
    ExecutorService es = Executors.newFixedThreadPool(20);
    Options config = new Options();
    String user = "fernandoeng";
    List tracklyric;
    Map<String, String> tracklyricmap;

    public void addTrack(ITTrack track) {
    }

    public List<ITTrack> getTracks() {
        iTunes it = new iTunes();

        List<ITTrack> tracks = null;
        if (jRadioButton5.isSelected()) {
            tracks = it.getSelectedTracks().toList();
        } else if (jRadioButton6.isSelected()) {
            ITPlaylist itplaylist = it.getCurrentPlaylist();
            tracks = itplaylist.getTracks().toList();
        } else if (jRadioButton7.isSelected()) {
            ITLibraryPlaylist itlibrary = it.getLibraryPlaylist();
            tracks = itlibrary.getTracks().toList();
        } else if (jRadioButton16.isSelected()) {
            ITTrack track = it.getCurrentTrack();

            List<ITTrack> trackss = new ArrayList<ITTrack>(1);
            trackss.add(track);
        }


        return tracks;
    }

    @Action
    public void PlayPause() {
        iTunes it = new iTunes();
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(lastplaylist.LastPlaylistApp.class).getContext().getResourceMap(LastPlaylistView.class);

        if (it.getPlayerState().equals(ITPlayerState.ITPlayerStateStopped)) {
            PlayPauseButton.setIcon(resourceMap.getIcon("Stop.icon"));
        } else if (it.getPlayerState().equals(ITPlayerState.ITPlayerStatePlaying)) {
            PlayPauseButton.setIcon(resourceMap.getIcon("Play.icon"));
        }

        it.playPause();
    }

    @Action
    public void prev() {
        iTunes itunes = new iTunes();
        itunes.previousTrack();
    }

    @Action
    public void next() {
        iTunes itunes = new iTunes();
        itunes.nextTrack();
    }

    @Action
    public void getTracksFromItunes() {
        iTunes it = new iTunes();

        try {
            List<ITTrack> tracks = null;
            switch (jComboBox4.getSelectedIndex()) {
                case 1: {
                    ITTrack track = it.getCurrentTrack();
                    tracks = new ArrayList<ITTrack>(1);
                    tracks.add(track);
                    break;
                }
                case 2: {
                    tracks = it.getSelectedTracks().toList();
                    break;
                }
                case 3: {
                    ITPlaylist itplaylist = it.getCurrentPlaylist();
                    tracks = itplaylist.getTracks().toList();
                    break;
                }
                case 4: {
                    ITLibraryPlaylist itlibrary = it.getLibraryPlaylist();
                    tracks = itlibrary.getTracks().toList();
                }
                default: {
                    ITTrack track = it.getCurrentTrack();
                    tracks = new ArrayList<ITTrack>(1);
                    tracks.add(track);
                }
            }
            List Tracknames = new ArrayList();

            es = Executors.newFixedThreadPool(20);

            tracklyricmap = new HashMap<String, String>();

            for (int i = 0; i < tracks.size(); i++) {
                ITTrack iTTrack = tracks.get(i);
                Tracknames.add(iTTrack.getArtist() + " - " + iTTrack.getName());

                final String artista = iTTrack.getArtist();
                final String faixa = iTTrack.getName();

                Task tarefa = new Task(LastPlaylistApp.getApplication()) {

                    @Override
                    protected Object doInBackground() throws Exception {
                        try {
                            setMessage("procurando letra de " + artista + " - " + faixa);
                            Pagina pagina = Search.search(artista, faixa);

                            if (pagina != null) {
                                setMessage("encontrada letra de " + artista + " - " + faixa);
                                tracklyricmap.put(artista + " - " + faixa, pagina.getLetra());
                            }
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        return null;
                    }

                    @Override
                    protected void setMessage(String message) {
                        super.setMessage(message);
                        statusMessageLabel.setText(message);
                    }
                };

                es.execute(tarefa);
            }
            TrackList.setListData(Tracknames.toArray());
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    @Action
    public Task getLastfmData() {
        jButton1.setEnabled(false);
        return new GetLastfmDataTask(getApplication());
    }

    private class GetLastfmDataTask extends org.jdesktop.application.Task<Object, Void> {

        GetLastfmDataTask(org.jdesktop.application.Application app) {
            // Runs on the EDT.  Copy GUI state that
            // doInBackground() depends on from parameters
            // to GetXMLTask fields, here.
            super(app);
        }

        @Override
        protected Object doInBackground() {
            String str = "";
//            String apikey = "46e1a92ea99f817ad7e129cb56c33849";

            if (jTextField1.getText().length() > 0) {
                user = jTextField1.getText();
            }

            Chart chart;
            Collection<Track> tracks = null;

            setMessage("Buscando dados na last.fm");

            try {
                int limit = 0;
                if (jComboBox1.getSelectedIndex() > 0) {
                    limit = Integer.parseInt(jComboBox1.getSelectedItem().toString());
                }

                switch (UserPeriodComboBox.getSelectedIndex()) {
                    case 1: {
                        chart = User.getWeeklyTrackChart(user, limit, config.getApikey());
                        DateFormat format = DateFormat.getDateInstance();
                        String from = format.format(chart.getFrom());
                        String to = format.format(chart.getTo());
                        str = "Mais tocadas da semana passada de " + user + ", de " + from + " até " + to + "\n";
                        tracks = chart.getEntries();
                        break;
                    }
                    case 2: {
                        tracks = User.getTopTracks(user, Period.THREE_MONTHS, config.getApikey());
                        str = "Mais tocadas dos ultimos 3 meses de " + user + "\n";
                        break;
                    }
                    case 3: {
                        tracks = User.getTopTracks(user, Period.SEVEN_DAYS, config.getApikey());
                        str = "Mais tocadas nos ultimos 7 dias " + user + "\n";
                        break;
                    }
                    default: {
                        tracks = User.getLovedTracks(user, config.getApikey(), limit);
                        str = "Faixas favoritas de " + user + "\n";
                        break;
                    }

                }

                setMessage(str);

                DefaultTableModel tab = (DefaultTableModel) jTable1.getModel();
                while (tab.getRowCount() > 0) {
                    tab.removeRow(0);
                }

                for (Track track : tracks) {
                    tab.addRow(new Object[]{true,
                                track.getName(),
                                track.getArtist(),
                                track.getAlbum(),
                                track.getPlaycount() > 0 ? track.getPlaycount() : ""
                                + track.getPlayedWhen() != null ? track.getPlayedWhen().toLocaleString() : ""
                            });
                }

                setMessage(tracks.size() + " faixas encontradas.");
            } catch (Exception e) {
                jButton1.setEnabled(true);
                e.printStackTrace();
            }

            return null;
        }

        @Override
        protected void succeeded(Object result) {
            jButton1.setEnabled(true);
        }
    }

    @Action
    public Task gerarLista() {
        return new GerarListaTask(getApplication());
    }

    private class GerarListaTask extends org.jdesktop.application.Task<Object, Void> {

        GerarListaTask(org.jdesktop.application.Application app) {
            super(app);
        }

        @Override
        protected Object doInBackground() {
            if (jTable1.getRowCount() < 1) {
                return null;
            }

            String lista = "";

            switch (UserPeriodComboBox.getSelectedIndex()) {
                case 1: {
                    lista = "Top Week";
                    break;
                }
                case 2: {
                    lista = "Top 3 month";
                    break;
                }
                case 3: {
                    lista = "Top 7 days";
                    break;
                }
                default: {
                    lista = "Favoritas";
                    break;
                }
            }

            iTunes it = new iTunes();
            ITPlaylist pl = it.createPlaylist(jTextField1.getText() + " " + lista);
            ITLibraryPlaylist lb = it.getLibraryPlaylist();

            String nome;
            String artista;
            String album;

            ITUserPlaylist upl = (ITUserPlaylist) pl;

            int errors = 0;

            for (int i = 0; i < jTable1.getRowCount(); i++) {
                if (Boolean.parseBoolean(jTable1.getValueAt(i, 0).toString())) {
                    jTable1.setRowSelectionInterval(i, i);

                    nome = (String) jTable1.getValueAt(i, 1);
                    artista = (String) jTable1.getValueAt(i, 2);
                    album = (String) jTable1.getValueAt(i, 3);

                    try {
                        ITTrackCollection search = lb.search(nome + " " + artista, ITPlaylistSearchField.ITPlaylistSearchFieldAll);

                        if (search.getCount() > 0) {
                            ITTrack track = search.ItemByName(nome);
                            setMessage(artista + " - " + nome);
                            upl.addTrack(track);
                        } else {
                            setMessage("pesquisa sem resultado");
                        }
                    } catch (Exception e) {
                        setMessage(e.getMessage());
                        errors++;
                    }
                }
            }
            if (errors > 0) {
                setMessage("Ocorreram " + errors + " erros!");
            } else {
                setMessage("Pronto!");
            }
            return null;
        }
    }

    @Action
    public Task getDataFromLastFmToItunes() {
        return new GetDataFromLastFmToItunesTask(getApplication());
    }

    private class GetDataFromLastFmToItunesTask extends org.jdesktop.application.Task<Object, Void> {

        GetDataFromLastFmToItunesTask(org.jdesktop.application.Application app) {
            super(app);
        }
        int tarefasterminadas = 0;
        int quantidade = 0;

        @Override
        protected Object doInBackground() {
            iTunes it = new iTunes();

            ITTrackCollection tracks = null;
            if (jRadioButton5.isSelected()) {
                tracks = it.getSelectedTracks();
            }
            if (jRadioButton6.isSelected()) {
                ITPlaylist itplaylist = it.getCurrentPlaylist();
                tracks = itplaylist.getTracks();
            }
            if (jRadioButton7.isSelected()) {
                ITLibraryPlaylist itlibrary = it.getLibraryPlaylist();
                tracks = itlibrary.getTracks();
            }

            quantidade = tracks.getCount();

            if (quantidade < 1) {
                return null;
            }


            if (jTextField1.getText().length() > 0) {
                user = jTextField1.getText();
            }
            tarefasterminadas = 0;

            if (es != null) {
                es.shutdownNow();
            }
            es = Executors.newFixedThreadPool(20);

            setMessage("total de faixas locais: " + quantidade);
            setMessage("Total de faixas: " + quantidade);
            setProgress(0, 0, quantidade);

            for (int i = 1; i < quantidade + 1; i++) {
                if (es.isShutdown()) {
                    break;
                }
                setProgress(i, 0, quantidade);
                try {
                    final ITTrack track = tracks.getItem(i);
                    final int tracknumber = i;
                    setMessage("faixa " + i + ": " + track.getName() + " - " + track.getArtist());

                    Task tarefa = new Task(LastPlaylistApp.getApplication()) {

                        @Override
                        protected Object doInBackground() throws Exception {
                            try {
                                int faixa = tracknumber;
                                boolean parar = false;
                                setMessage("Procurando faixa " + faixa);

                                PaginatedResult<Track> lfbiblioteca = net.roarsoftware.lastfm.Library.getTracks(user, track.getArtist(), "", 1, 0, config.getApikey());

                                Collection<Track> lfpagina;
                                for (int j = 1; j < (lfbiblioteca.getTotalPages() + 1) && !parar; j++) {
                                    if (j > 1) {
                                        lfbiblioteca = net.roarsoftware.lastfm.Library.getTracks(user, track.getArtist(), track.getAlbum(), j, 0, config.getApikey());
                                    }
//                                    setMessage("artista " + track.getArtist() + ", pagina " + lfbiblioteca.getPage() + ":" + lfbiblioteca.getTotalPages());

                                    lfpagina = lfbiblioteca.getPageResults();
                                    for (Track lftrack : lfpagina) {
//                                        setMessage(track.getName() + " = " + (lftrack.getName()));
                                        if (track.getName().equalsIgnoreCase(lftrack.getName())) {
                                            if (track.getPlayedCount() != lftrack.getPlaycount()) {
                                                setMessage("faixa " + faixa + ": " + track.getName() + " - " + track.getArtist() + ": " + track.getPlayedCount() + "->" + lftrack.getPlaycount());
                                                setMessage("faixa " + faixa + ": " + track.getName() + " - " + track.getArtist() + ": " + track.getPlayedCount() + "->" + lftrack.getPlaycount());
                                                track.setPlayedCount(lftrack.getPlaycount());
                                                track.setPlayedDate(lftrack.getPlayedWhen());
                                                Toolkit.getDefaultToolkit().beep();
                                            }
                                            parar = true;
                                            break;
                                        }
                                    }
                                }
                                setMessage("termino faixa " + faixa);
                            } catch (Exception e) {
                                setMessage(e.getMessage());
                            }

                            tarefasterminadas++;
                            setProgress2(tarefasterminadas, 0, quantidade);

                            return null;
                        }

                        @Override
                        protected void setMessage(String message) {
                            super.setMessage(message);
                            setMessage2(message);
                        }
                    };

                    es.execute(tarefa);

                } catch (Exception e) {
                }
            }
            setProgress(0);
            try {
                es.awaitTermination(quantidade * 4, TimeUnit.SECONDS);
            } catch (InterruptedException ex) {
                Logger.getLogger(LastPlaylistView.class.getName()).log(Level.SEVERE, null, ex);
            }

            return null;
        }

        protected void setMessage2(String message) {
            super.setMessage(message);
        }

        void setProgress2(int value, int min, int max) {
            setProgress(value, min, max);
        }
    }

    @Action
    public Task getArtOfTrackFromLastFm() {
        return new GetArtOfTrackFromLastFmTask(getApplication());
    }

    private class GetArtOfTrackFromLastFmTask extends org.jdesktop.application.Task<Object, Void> {

        GetArtOfTrackFromLastFmTask(org.jdesktop.application.Application app) {
            super(app);
        }

        @Override
        protected Object doInBackground() {

            List<ITTrack> tracks = getTracks();

//            ITArtwork artwork;
            ITArtworkCollection artworks;
            BufferedImage image = null;
            URL imageUrl = null;

            JFrame frame = new JFrame("artwork");
            frame.setLayout(new GridLayout(1, 1));
            JLabel art = new JLabel();
            frame.add(art);
            frame.setSize(300, 300);

            try {
                if (tracks.isEmpty()) {
                    return null;
                }
                int i = 0;
                for (ITTrack track : tracks) {
                    i++;

                    artworks = track.getArtwork();

                    if (artworks.getCount() == 0) {
                        try {
                            int faixa = i + 1;
                            boolean parar = false;
                            setMessage("Procurando faixa " + faixa);

                            PaginatedResult<Track> lfbiblioteca = net.roarsoftware.lastfm.Library.getTracks(user, track.getArtist(), track.getAlbum(), 1, 0, config.getApikey());


                            setMessage("Biblioteca encontrada " + track.getArtist());

                            Collection<Track> lfpagina;
                            for (int j = 1; j < (lfbiblioteca.getTotalPages() + 1) && !parar; j++) {
                                if (j > 1) {
                                    lfbiblioteca = net.roarsoftware.lastfm.Library.getTracks(user, track.getArtist(), track.getAlbum(), j, 0, config.getApikey());
                                }
                                setMessage("artista " + track.getArtist() + ", pagina " + lfbiblioteca.getPage() + ":" + lfbiblioteca.getTotalPages());

                                lfpagina = lfbiblioteca.getPageResults();
                                for (Track lftrack : lfpagina) {
                                    if (track.getName().equalsIgnoreCase(lftrack.getName())) {
                                        if (lftrack.getImageURL(ImageSize.EXTRALARGE) != null) {
                                            setMessage("extra large");
                                            setMessage(lftrack.getImageURL(ImageSize.EXTRALARGE));
                                            imageUrl = new URL(lftrack.getImageURL(ImageSize.EXTRALARGE));
                                        } else if (lftrack.getImageURL(ImageSize.LARGE) != null) {
                                            setMessage("large");
                                            setMessage(lftrack.getImageURL(ImageSize.LARGE));
                                            imageUrl = new URL(lftrack.getImageURL(ImageSize.LARGE));
                                        } else if (lftrack.getImageURL(ImageSize.MEDIUM) != null) {
                                            setMessage("medium");
                                            setMessage(lftrack.getImageURL(ImageSize.MEDIUM));
                                            imageUrl = new URL(lftrack.getImageURL(ImageSize.MEDIUM));
                                        } else {
                                            parar = true;
                                            break;
                                        }
                                        frame.show();
                                        art.setIcon(new ImageIcon(imageUrl));

                                        Toolkit.getDefaultToolkit().beep();

                                        parar = true;
                                        break;
                                    }

                                }
                            }
                        } catch (Exception ex) {
                            ex.printStackTrace();
                        }
                    }

                    if (false) {
                        try {
                            String musica = track.getArtist() + " - " + track.getName();
                            setMessage(musica);

                            artworks = track.getArtwork();
                            for (int j = 0; j < artworks.getCount(); j++) {
                                try {
                                    Dispatch artworkCollection = Dispatch.get(track.fetchDispatch(), "Artwork").getDispatch();
                                    Dispatch artwork = Dispatch.call(artworkCollection, "Item", new Variant(j + 1)).getDispatch();
                                    int format = Dispatch.call(artwork, "Format").getInt();

                                    String ext = ".jpg";
                                    if (ITArtworkFormat.values()[format].name().equalsIgnoreCase("ITArtworkFormatPNG")) {
                                        ext = ".png";
                                    } else if (ITArtworkFormat.values()[format].name().equalsIgnoreCase("ITArtworkFormatJPEG")) {
                                        ext = ".jpg";
                                    } else if (ITArtworkFormat.values()[format].name().equalsIgnoreCase("ITArtworkFormatBMP")) {
                                        ext = ".bmp";
                                    }

                                    File tmpFile = File.createTempFile(musica + "-iTunesArt", ext, new File("E:\\Documentos\\Projetos\\Java\\lastPlaylist"));

                                    Dispatch.call(artwork, "SaveArtworkToFile", new Variant(tmpFile.getAbsolutePath()));
                                    image = ImageIO.read(tmpFile);

                                    art.setIcon(new ImageIcon(image));
                                } catch (Exception e) {
                                    e.printStackTrace();
                                }
                            }

                        } catch (Exception e) {
                            e.printStackTrace();
                            setMessage(e.getMessage());
                        }
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                setMessage(e.getMessage());
            }
            return null;
        }
    }

    @Action
    public Task getTagsFromLastfmToItunes() {
        return new GetTagsFromLastfmToItunesTask(getApplication());
    }

    private class GetTagsFromLastfmToItunesTask extends org.jdesktop.application.Task<Object, Void> {

        GetTagsFromLastfmToItunesTask(org.jdesktop.application.Application app) {
            super(app);
        }

        @Override
        protected Object doInBackground() {

            List<ITTrack> tracks = getTracks();
            Collection<String> lftags = null;

            try {
                int i = 0;
                for (ITTrack track : tracks) {
                    i++;

//                    Track.getTopTags(token, token, token)ags(track.getArtist(), track.getName(), session);
                    List<Tag> tags = Tag.filter(Track.getTopTags(track.getArtist(), track.getName(), config.getApikey()), 3);
//                    List<Tag> tags = Track.getTopTags(track.getArtist(), track.getName(), config.getApikey());
//                    List<Tag> tags = Tag.getTopTags(config.getApikey());//Track.getTopTags(track.getArtist(), track.getName(), config.getApikey());
//                    List<Tag> tags = Tag.getTopTags(config.getApikey());//Track.getTopTags(track.getArtist(), track.getName(), config.getApikey());
                    String str = "";


                    setMessage(track.getArtist() + " - " + track.getName() + " tags: ");
                    for (Tag tag : tags) {
                        setMessage(tag.getName() + ":" + tag.getCount() + ", ");
                    }


                    if (false) {
                        try {
                            int faixa = i + 1;
                            boolean parar = false;
                            setMessage("Procurando faixa " + faixa);

                            PaginatedResult<Track> lfbiblioteca = net.roarsoftware.lastfm.Library.getTracks(user, track.getArtist(), track.getAlbum(), 1, 0, config.getApikey());

                            Collection<Track> lfpagina;
                            for (int j = 1; j < (lfbiblioteca.getTotalPages() + 1) && !parar; j++) {
                                if (j > 1) {
                                    lfbiblioteca = net.roarsoftware.lastfm.Library.getTracks(user, track.getArtist(), track.getAlbum(), j, 0, config.getApikey());
                                }

                                lfpagina = lfbiblioteca.getPageResults();
                                for (Track lftrack : lfpagina) {
                                    if (track.getName().equalsIgnoreCase(lftrack.getName())) {
                                        lftags = lftrack.getTags();
                                        String str2 = "";
                                        for (String tag : lftags) {
                                            str2 += tag + ", ";
                                        }
                                        setMessage(lftrack.getArtist() + " - " + lftrack.getName() + " tags: " + str2);

                                    }
                                }
                            }
                        } catch (Exception ex) {
                        }
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }


            return null;
        }
    }

    @Action
    public Task getTags() {
        return new GetTagsTask(getApplication());
    }

    private class GetTagsTask extends org.jdesktop.application.Task<Object, Void> {

        GetTagsTask(org.jdesktop.application.Application app) {
            super(app);
        }

        @Override
        protected Object doInBackground() {
            String searchtag = jTextField2.getText();
            Collection<String> tags = Tag.search(searchtag, config.getApikey());

            DefaultTableModel tab = (DefaultTableModel) jTable2.getModel();
            while (tab.getRowCount() > 0) {
                tab.removeRow(0);
            }

            for (String tag : tags) {
                tab.addRow(new Object[]{tag
                        });
            }

            return null;
        }
    }

    @Action
    public Task getArtist() {
        return new GetArtistTask(getApplication());
    }

    private class GetArtistTask extends org.jdesktop.application.Task<Object, Void> {

        GetArtistTask(org.jdesktop.application.Application app) {
            super(app);
        }

        @Override
        protected Object doInBackground() {
            String artistsearch = jTextField3.getText();
            Collection<Artist> searchResult = Artist.search(artistsearch, config.getApikey());

            DefaultTableModel tab = (DefaultTableModel) jTable3.getModel();
            while (tab.getRowCount() > 0) {
                tab.removeRow(0);
            }

            for (Artist artist : searchResult) {
                try {
                    artist = Artist.getInfo(artist.getName(), config.getApikey());

                    String artista = "";
                    String str = "";

                    artista = artist.getName();
                    str = artist.getWikiText();
                    str += artist.getWikiSummary();
                    str += " Playcount: " + artist.getPlaycount();
                    str += " ouvintes: " + artist.getListeners();

                    tab.addRow(new Object[]{
                                artista,
                                str
                            });

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return null;
        }
    }
}
